<?php
/**
 * File: view.php
 * Author: Mihaela
 * Date: 11/1/2012
 * Modified By: CIS505 TEAM 1
 * Modified Date: 2012-11-29
 * Description: This module has all the funtions that produce HTML code and/or
 *   output HTML code with echo statements.
 */

/**
 * Displays welecome message whe application is first used.
 */
function displayWelcomeMessage( )
{
  echo <<<_END
  <!--<div id=welcome>
  </div>--> <!-- End welcome banner -->

_END;
}


/**
 * Gets internship data from the user.
 */
function displayInternshipDataForm( )
{
  echo <<<_END
    <body onLoad="document.forms.addInternshipForm.postingDate.focus()">


<form method="post" action="control.php" name="addInternshipForm" id="addInternshipForm">
  <fieldset>
  <legend>Add New Internship:</legend>
      <div id="left">
        <PRE>
        Posting Date: <input type="text" placeholder="Example: 2012-11-12" name="postingDate" />   Internship Title:    <input type="text" name="internshipTitle" />
        Sponsor Name: <input type="text" name="sponsorName" />   Internship Category: <input type="text" name="internshipCategory" />
        Sponsor City: <input type="text" name="sponsorCity" />   Sponsor State: <select name="sponsorState"><option value="AL">AL</option>
  <option value="AK">AK</option>
  <option value="AZ">AZ</option>
  <option value="AR">AR</option>
  <option value="CA">CA</option>
  <option value="CO">CO</option>
  <option value="CT">CT</option>
  <option value="DE">DE</option>
  <option value="DC">DC</option>
  <option value="FL">FL</option>
  <option value="GA">GA</option>
  <option value="HI">HI</option>
  <option value="ID">ID</option>
  <option value="IL">IL</option>
  <option value="IN">IN</option>
  <option value="IA">IA</option>
  <option value="KS">KS</option>
  <option value="KY">KY</option>
  <option value="LA">LA</option>
  <option value="ME">ME</option>
  <option value="MD">MD</option>
  <option value="MA">MA</option>
  <option value="MI">MI</option>
  <option value="MN">MN</option>
  <option value="MS">MS</option>
  <option value="MO">MO</option>
  <option value="MT">MT</option>
  <option value="NE">NE</option>
  <option value="NV">NV</option>
  <option value="NH">NH</option>
  <option value="NJ">NJ</option>
  <option value="NM">NM</option>
  <option value="NY">NY</option>
  <option value="NC">NC</option>
  <option value="ND">ND</option>
  <option value="OH">OH</option>
  <option value="OK">OK</option>
  <option value="OR">OR</option>
  <option value="PA">PA</option>
  <option value="RI">RI</option>
  <option value="SC">SC</option>
  <option value="SD">SD</option>
  <option value="TN">TN</option>
  <option value="TX">TX</option>
  <option value="UT">UT</option>
  <option value="VT">VT</option>
  <option value="VA">VA</option>
  <option value="WA">WA</option>
  <option value="WV">WV</option>
  <option value="WI">WI</option>
  <option value="WY">WY</option>
  </select>
        Is Paid:      <select name="isPaid"><option value="YES">YES</option> <option value="NO">NO</option></select>
        <input type="submit" name="submitBttn" value="Add Internship" class="btn btn-primary btn-small"/>

        </PRE>
      </div> <!-- end #left -->
    
      <div id="left">
        <PRE>
        </PRE>
      </div> <!-- end #right -->
        

  </fieldset>
</form>



_END;
}


/**
 * Formats table header.
 * @return string $out has HTML code for dynamic page, including listing header.
 */
function startInternshipListing( )
{
  $out = <<<_END

<fieldset>
  <legend>Internship Listing</legend>
    <table>
      <tr>
        <strong>
          <th>Internship ID</th>
          <th>Sponsor Name</th>
          <th>Sponsor City</th>
          <th>Sponsor State</th>
          <th>Posting Date</th>
          <th>Internship Title</th>
          <th>Internship Category</th>
          <th>Is Paid</th>
          <th>Update</th>
          <th>Delete</th>
        </strong>
      </tr>

_END;
  return $out;
}

/**
 * Formats one entry of data from the internship table.
 * @param integer $internshipID 
 * @param string $sponsorName internship lastName
 * @param string $sponsorCity internship firstName
 * @param string $sponsorState internship gpa
 * @param string $postingDate internship studentyear
 * @param string $internshipTitle studen major
 * @return string $out has HTML code to display row # and internship data for one
 *   internship record.
 */
function displayOneInternshipListing($internshipID, $sponsorName, $sponsorCity, $sponsorState, $postingDate, $internshipTitle, $internshipCategory, $isPaid)
{
 $out = <<<_END
    <tr>
      <td>$internshipID</td>
        <form method="post" action="control.php">

          <td><input type="text" name="sponsorName" id="sponsorName" value="$sponsorName" / ></td>
          <td><input type="text" name="sponsorCity" id="sponsorCity" value="$sponsorCity" / ></td>
          <td><input type="text" name="sponsorState" id="sponsorState" value="$sponsorState" / ></td>
          <td><input type="text" name="postingDate" id="postingDate" value="$postingDate" / ></td>
          <td><input type="text" name="internshipTitle" id="internshipTitle" value="$internshipTitle" size="45"/ ></td>
          <td><input type="text" name="internshipCategory" id="internshipCategory" value="$internshipCategory"/ ></td>
          <td><input type="text" name="isPaid" id="isPaid" value="$isPaid" / ></td>
          <td>
            <input type="hidden" name="internshipID" id="internshipID" value="$internshipID" />
            <input type="submit" name="update" class="btn btn-primary btn-small" id="update" value="UPDATE"/>

          </td>
          <td>
            <input type="hidden" name="internshipID" value="$internshipID" />
            <input type="submit" name="delete" class="btn btn-danger btn-small" value="DELETE">
          </td>
        </form>
      </td>
    </tr>

_END;
 return $out;
}


/**
 * Displays error message if not empty.
 */
function displayErrorMessage($errorMsg)
{
  if ($errorMsg != "") { //echoed only if there is an error to report
    echo "<strong>====ERROR</strong>: $errorMsg. Try again!<br /><br />";
  }
}


/**
 * Displays internship listing.
 */

function displayInternshipListing($internshipListing) 
{
  $out = ""; //to format final internship listing
echo <<<_END

  <form method="post" action="control.php">

      <fieldset>

        <legend> Search Here:</legend>

          <div id="left">
          <PRE>
           Search Query: <input type = "text" maxlength = "50" name = "search" />
           Search By:    <select name = "criteria" value = "criteria" size="1" />

              <option name  = "internshipID" value = "internshipID">Internship ID</option>
			  
              <option SELECTED name = "sponsorName" value = "sponsorName">Sponsor Name</option>

              <option name = "sponsorCity" value = "sponsorCity">Sponsor city</option>

              <option name = "sponsorState" value = "sponsorState">Sponsor State</option>

              <option name = "postingDate" value = "postingDate">Posting Date</option>

              <option name = "internshipTitle" value = "internshipTitle">Internship Title</option>

              <option name = "internshipCategory" value = "internshipCategory">Internship Category</option>

              <option name = "isPaid" value = "isPaid">Is Paid</option>

            <select> 
           Outer Sort:   <select name = "outerSort" value = "outerSort" size="1" />

              <option name  = "internshipID" value = "internshipID">Internship ID</option>

              <option SELECTED name = "sponsorName" value = "sponsorName">Sponsor Name</option>

              <option name = "sponsorCity" value = "sponsorCity">Sponsor city</option>

              <option name = "sponsorState" value = "sponsorState">Sponsor State</option>

              <option name = "postingDate" value = "postingDate">Posting Date</option>

              <option name = "internshipTitle" value = "internshipTitle">Internship Title</option>

              <option name = "internshipCategory" value = "internshipCategory">Internship Category</option>

              <option name = "isPaid" value = "isPaid">Is Paid</option>
            </select>
           Inner Sort:   <select name = "innerSort" value = "innerSort" size="1" />

              <option name  = "internshipID" value = "internshipID">Internship ID</option>
              <option name = "sponsorName" value = "sponsorName">Sponsor Name</option>

              <option name = "sponsorCity" value = "sponsorCity">Sponsor city</option>

              <option name = "sponsorState" value = "sponsorState">Sponsor State</option>

              <option  SELECTED name = "postingDate" value = "postingDate">Posting Date</option>

              <option name = "internshipTitle" value = "internshipTitle">Internship Title</option>

              <option name = "internshipCategory" value = "internshipCategory">Internship Category</option>

              <option name = "isPaid" value = "isPaid">Is Paid</option>
			  
            </select>
           Limit: <select name = "howMany" value = "howMany" size="1"/> 
              <option SELECTED value = "10">10</option>
              <option value = "25">25</option>
              <option value = "50">50</option>
              <option value = "100">100</option>
              <option value = "1000">1000</option>
                   </select><input type="submit" name="searchButton" value="Search" class="btn btn-primary btn-small"/>
          </PRE>
        </div> <!-- end #left -->

        <div id="left">
          <!--<input type="submit" name="searchButton" value="search" class="btn btn-primary btn-small"/><br />-->
        </div> <!-- end #right -->


      </fieldset>

  </form>


_END;
  
  $out = startinternshipListing( ) . $internshipListing . closeinternshipListing( );
  echo $out;
}

/**
 * Completes HTML code of the dyanmic page with table and fieldset end tags.
 * @return string $out has HTML code with end tags. 
 */
function closeInternshipListing( )
{
  $out = "</table></fieldset></body>";
  return $out;
}


?>